import 'package:flutter/material.dart';
import 'package:stock_check/common/utils/CommonUtils.dart';
import 'package:stock_check/common/utils/NavigatorUtils.dart';

class NeedCheckItemWidget extends StatelessWidget {
  final BuildContext context;
  final dynamic item;
  final String type;
  final dynamic detail;

  const NeedCheckItemWidget({Key key, this.context, this.item, this.type, this.detail}) : super(key: key);

  // 渲染巡检状态
  _renderCheckStatus(detail,assetsList,String type) {
    String text;
    Color color;
    if(detail.content!=null){
      var haveCheck = assetsList.itemList.where((e){
        return e.status == 0;
      });
      bool status = assetsList.itemList.every((e){
        return e.status == 1;
      });
      if(haveCheck.length==0){
        if(status){
          text = '全部正常';
          color = Colors.green;
        }else{
          text = '存在异常';
          color = Colors.red;
        }
      }else{
        text = '尚未巡检';
        color = Colors.blue;
      }
    }else{
      text = '已上报';
      color = Colors.grey;
    }



    return Transform(
      transform: Matrix4.rotationZ(-0.3),
      child: Container(
        width: 80.0,
        height: 40.0,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            border: Border.all(color: color, width: 5.0)
        ),
        child: Text(text, style: TextStyle(color: color, fontWeight: FontWeight.bold)),
      ),
    );
  }
  @override
  Widget build(BuildContext context) {
    var textStyle=TextStyle(
        color: Colors.grey[600]
    );
    return InkWell(
        highlightColor:Colors.white,
        onTap: (){
          if(detail.curStartTimeStr.isEmpty)
            detail.curStartTimeStr = CommonUtils.getCurrentTime();
          NavigatorUtils.goAssetCheckListPage(
              context,
              item,
              detail.recordId,
              type);
        },
        child: Column(
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Stack(
              fit: StackFit.passthrough,
              alignment: Alignment.center,
              children: <Widget>[
                Card(
                  child: Container(
                      width: double.infinity,
                      padding: EdgeInsets.all(16.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment:
                        MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Text('资产编号：${item.eqptNo}',style: textStyle,),
                          Divider(),
                          Text('资产名称：${item.name}',style: textStyle),
                          Divider(),
                          Text('资产地址：${item.position}',style: textStyle),
                        ],
                      )),
                ),
                Positioned(
                    top: 60.0,
                    right: 20,
                    width: 100.0,
                    height: 40.0,
                    child: Container(
                        child: _renderCheckStatus(detail,item,type)
                    ))
              ],
            )
          ],
        )
    );
  }
}
